<?php
print_r($_POST);
require_once('./includes/common.php');
require(SYSTEM_ROOT . 'xiaowei/XiaoWei.php');
$pay_config = require(SYSTEM_ROOT . 'xiaowei/config.php');
$pay = new XiaoWei($pay_config['mch_id'], $pay_config['key'], $pay_config['url']);

if ($pay->notify()) {
    if ($_POST['status'] == 1) {
        $out_trade_no = daddslashes($_POST['out_trade_no']);
        $total_fee = $_POST['total_fee'];
        $srow = $DB->query("SELECT * FROM pay_order WHERE trade_no='{$out_trade_no}' limit 1 for update")->fetch();
        if ($srow['status'] == 0) {
            if ($DB->exec("update `pay_order` set `status` ='1' where `trade_no`='$out_trade_no'")) {
                $DB->exec("update `pay_order` set `endtime` ='$date' where `trade_no`='$out_trade_no'");
                processOrder($srow);
            }
        }

        echo '{"status":0,"message":"OK"}';
    } else {
        echo '{"status":-2,"message":"OK"}';
    }
} else {
    echo '{"status":-3,"message":"OK"}';
}
?>